from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms
import cv2

image_path = "dataset/train/ants/0013035.jpg"
image = Image.open(image_path)
tensor_trans = transforms.ToTensor()
tensor_image = tensor_trans(image)
print(type(tensor_image))
print(tensor_image.shape)
Writer = SummaryWriter("logs")
Writer.add_image("tensor", tensor_image, 1)
image_cv = cv2.imread(image_path)
print(image_cv.shape)
Writer.add_image("numpy", image_cv, 1,dataformats="HWC")
Writer.close()
